package com.zxmzy.scaffold.project

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.zxmzy.scaffold.core.base.BaseViewModel
import com.zxmzy.scaffold.http.RequestManager

/**
 * @author zhangxiaoming
 * @date 2023/8/25
 * @description
 */
class MainViewModel : BaseViewModel() {
    private val _bannerLiveData = MutableLiveData<List<Banner>>()
    val bannerLiveData:LiveData<List<Banner>> get() = _bannerLiveData
    private val api: TestService by lazy {
        RequestManager.get().apiService(TestService::class.java)
    }

    fun getBanner() {
        launch<WanResponse<List<Banner>>> {
            onRequest {
                api.getBanner()
            }
            onResponse {
                _bannerLiveData.value = it.data
            }
        }

    }


    fun login(): LiveData<Boolean> {
        val liveData = MutableLiveData<Boolean>()
        launch {
            onRequest {
                api.login(LoginParam("zxmzy", "qweqwe123"))
            }
            onResponse {
                liveData.value = true
            }
        }
        return liveData
    }
}